﻿#if NETFX_CORE || WINDOWS_PHONE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using System.Runtime.InteropServices.WindowsRuntime;
using System.IO;

namespace WindowsCommonStorage
{
    internal class NetFxCoreStorageFile:CommonStorageFile
    {

        internal StorageFile _file;
        public NetFxCoreStorageFile()
        {
            this._file = null;
            
        }

        internal protected  override StorageFile ProtectedEnvironmentFile
        {
            get 
            {
                return this._file; 
            }
        }

        internal protected override string ProtectedPath
        {
            get { return this.EnvironmentFile.Path; }
        }

        internal protected override DateTimeOffset ProtectedDateCreated
        {
            get { return this.EnvironmentFile.DateCreated; }
        }

        internal protected override async Task ProtectedCopyAndReplaceAsync(CommonStorageFile fileToReplace)
        {
            await this.EnvironmentFile.CopyAndReplaceAsync(fileToReplace.EnvironmentFile);
        }

        internal protected override async Task ProtectedDeleteAsync()
        {
            await this.EnvironmentFile.DeleteAsync();
        }




        internal protected override string ProtectedName
        {
            get { return this.EnvironmentFile.Name; }
        }

        internal protected override async Task ProtectedRenameAsync(string desiredName)
        {
            await this.EnvironmentFile.RenameAsync(desiredName);
        }

        internal protected override async Task ProtectedRenameAsync(string desiredName, CommonNameCollisionOption option)
        {
            await this.EnvironmentFile.RenameAsync(desiredName,CommonNameColltionOptionExchanger.Exchange( option));
        }

        protected internal override bool ProtectedIsOfType(CommonStorageItemTypes itemType)
        {
            return this.EnvironmentFile.IsOfType(CommonStorageItemTypesExchanger.Exchange(itemType));
        }

        protected internal override CommonFileAttributes ProtectedAttributes
        {
            get { return CommonFileAttributesExchanger.Exchange( this.EnvironmentFile.Attributes); }
        }



        protected internal override async Task<Stream> ProtectedOpenStreamAsync()
        {
            return (await this.EnvironmentFile.OpenAsync(FileAccessMode.ReadWrite)).AsStream();
        }

        protected internal static async Task<CommonStorageFile> ProtectedGetFileFromPathAsync(string path)
        {
            return new NetFxCoreStorageFile() { _file = await StorageFile.GetFileFromPathAsync(path) };
        }
    }
}
#endif
